<template>
  <div class="filter">
<div class="filter_item">
      商品名字：<Input
        v-model="goodName"
        show-word-limit
        style="width: 300px"
      />
    </div>
    <div class="filter_item">
      商品单价：<Input
        v-model="goodPrice"
        style="width: 70px"
      />
    </div>
    <div class="filter_item">
      购买数量：<Input
        v-model="goodNumber"
        style="width: 70px"
      />
    </div>
    <div class="filter_item">
      购买时间：<DatePicker
        type="datetime"
        placeholder="Select date"
        @on-change="bookChange"
        style="width: 200px"
      ></DatePicker>
    </div>
    <div class="filter_item">
      <Button type="primary" @click="addGood">添加</Button>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
name:'AddGood',
data(){
    return {
        book:"",
        goodName:"",
        goodPrice:0,
        goodNumber:0,
    }
},
methods:{
    addGood(){
        if(this.book!=""&&this.goodName!=""&&this.goodPrice!=null&&this.goodNumber!=null){
            axios
            .post("/api/good/addGood",{
                goodName:this.goodName,
                goodPrice:this.goodPrice,
                goodNumber:this.goodNumber,
                book:this.book,
            })
            .then(res =>{
                let data = res.data.data;
                console.log(data);
                if(data==1){
                    alert("录入成功！");
                    this.$emit("on-close-modal",false);
                }
                else{
                    alert("录入失败！")
                }
            })
        }
        else{
            alert("请填写完整！")
        }
    },
    bookChange(e){
        this.book = e;
    }
},
}

</script>
<style  lang="scss" scoped>
</style>